#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 110;
const int D = 7010;
const int inf = 0x3f3f3f3f;

int h[D],nodenum,sta[N],fa[N],k,n,m,peo[N],now[D],cnt = 1,S,T,d[D],maxflow;
vector<int> port[N];
struct edge{int v,w,nxt;}e[D<<4];
void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;e[++cnt] = (edge){x,0,h[y]};h[y] = cnt;}

int gf(int x){return fa[x] == x ? x : fa[x] = gf(fa[x]);}
void unionn(int x,int y){x = gf(x),y = gf(y); fa[x] = y;}

bool bfs(){
	queue<int> q; q.push(S); memset(d,0,sizeof(d)); now[S] = h[S]; d[S] = 1;
	while(q.size()){
		int x = q.front();q.pop();
		for(int i = h[x],y;i;i = e[i].nxt){
			if(!d[y = e[i].v] && e[i].w){
				d[y] = d[x] + 1; now[y] = h[y]; q.push(y); if(y == T) return 1;
			}
		}
	}return 0;
}

int dfs(int x,int flow){
	if(x == T) return flow; int res = flow;
	for(int i = h[x],y;i && res;i = e[i].nxt){
		if(d[y = e[i].v] == d[x] + 1 && e[i].w){
			int k = dfs(y,min(res,e[i].w)); if(!k) d[y] = 0;
			res -= k;e[i].w -= k;e[i^1].w += k;
		}
	}return flow - res;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in,k = in;
	for(int i = 1;i <= n + 2;i++) fa[i] = i;
	for(int i = 1;i <= m;i++){
		peo[i] = in;int r = in;
		for(int j = 0,x;j < r;j++) x = in,x = x == - 1 ? n + 2 : x == 0 ? n + 1 : x, port[i].pb(x);
		int lst = -1;
		for(int x : port[i]){
			if(lst != -1) unionn(lst,x),lst = x;
			else lst = x;
		}
	}
	if(gf(n+2) != gf(n+1)) return puts("0"),0;
	S = 0; T = 1; nodenum = 1;
	int ans;
	for(ans = 0;;ans++){
		if(ans){
			for(int i = 1;i <= n + 2;i++){
				int lst = sta[i]; sta[i] = ++nodenum;
				link(lst,sta[i],inf);
			}
		}
		else for(int i = 1;i <= n + 2;i++) sta[i] = ++nodenum;
		link(S,sta[n+1],inf) , link(sta[n+2],T,inf);
		if(ans)
			for(int i = 1;i <= m;i++){
				int u = port[i][(ans - 1)% port[i].size()],v = port[i][ans % port[i].size()];
//			cerr<<u<<"..."<<v<<endl;
				u = sta[u] - n - 2,v = sta[v];
				link(u,v,peo[i]);
			}
		int flow = 0;
		while(bfs()) while(flow = dfs(S,inf)) maxflow += flow;
		if(maxflow >= k) break;
	}
	printf("%d\n",ans);
	return 0;
}

